package sevensoft.gz031.demos.web.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import sevensoft.gz031.demos.web.entity.Admin;
import sevensoft.gz031.demos.web.response.R;
import sevensoft.gz031.demos.web.service.AdminService;

/**
 * 管理员
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    AdminService adminService;


    /**
     * 管理员登录
     * @param admin
     * @return
     */
    @PostMapping("/login")
    public R<String> login(@RequestBody Admin admin){
        String login = adminService.login(admin);
        return login!=null? R.ok(login):R.no("账号和密码错误");
    }

    /**
     * 获取个人基本信息
     * @param token
     * @return
     */
    @GetMapping
    public R<Admin> getInfo(@RequestHeader("token") String token){
        return R.ok(adminService.getInfo(token));
    }

    /**
     * 退出
     * @param token
     * @return
     */
    @PostMapping("/logout")
    public R<?> logout(@RequestHeader("token") String token){
        return adminService.logout(token)?R.ok():R.no();
    }
}
